package com.hdaccp.gymxmjpa.Controller;

import com.hdaccp.gymxmjpa.Dao.CardsinfoDao;
import com.hdaccp.gymxmjpa.Service.CardsinfoDaoImpl;
import com.hdaccp.gymxmjpa.entity.Cardsinfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.validation.Valid;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;

@Controller
@RequestMapping("/card")
public class CardsinfoController {
   @Autowired
    private CardsinfoDaoImpl cardsinfoDaoImpl;
   @Autowired
   private CardsinfoDao cardsinfoDao;

    @RequestMapping("/jin2")
    public String jin2(){

        return "WEB-INF/jsp/cards";
    }

    @RequestMapping("/query")
    @ResponseBody
    public Map<String,Object> query(String cardname, int pageSize, int pageNumber){
        Map<String,Object>  map1=new HashMap<String,Object>();
        map1.put("cardname",cardname);
        map1.put("qi",(pageNumber-1)*pageSize);
        map1.put("shi",pageSize);
        return cardsinfoDaoImpl.query(map1);
    }
 @RequestMapping("/del")
    @ResponseBody
    public  Map<String,Object> del(long id,String cardname, int pageSize, int pageNumber){
     cardsinfoDao.deleteById(id);
     Map<String,Object>  map1=new HashMap<String,Object>();
     map1.put("cardname",cardname);
     map1.put("qi",(pageNumber-1)*pageSize);
     map1.put("shi",pageSize);
     return cardsinfoDaoImpl.query(map1);
    }
    @RequestMapping("/add")
    @ResponseBody
    public  void save(Cardsinfo cardsinfo){
        cardsinfoDao.save(cardsinfo);
    }
    @RequestMapping("/cha")
    @ResponseBody
    public Optional<Cardsinfo> one(long id){
        return cardsinfoDao.findById(id);
    }
    @RequestMapping("/upd")
    @ResponseBody
    public  void upd(Cardsinfo cardsinfo){
        cardsinfoDao.save(cardsinfo);
    }


}
